//
//  RegisterNextViewController.m
//  GoldOperationClient
//
//  Created by yaxue wang on 16/8/8.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "RegisterNextViewController.h"
#import "TPKeyboardAvoidingScrollView.h"
#import "LoginViewController.h"
#import "CActionSheet.h"
#import "AppDelegate.h"
#import "BankView.h"
#import "RegusterAgreementViewController.h"
#import "CTextField.h"

@interface RegisterNextViewController()<UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>
{
    NSInteger _eyeClick;
    NSInteger _selectClick;
    UITextField *_nameText;
    CTextField*_password;
    NSString *_client;
    BankView *_bgView1;
    BankView *_bgView2;
    BankView *_bgView3;
    NSMutableArray *_provinceAr;
    NSMutableArray *_cityAr;
    NSMutableArray *_clientAr;
    NSMutableArray *_cityCodeAr;
    UIPickerView*_pickerView1;
    UIPickerView*_pickerView2;
    UIPickerView*_pickerView3;

}
@property(nonatomic, strong)NSString *headUrl;
@property(nonatomic, assign)BOOL isProvince;
@property(nonatomic, strong)NSString * provinceStr;
@property(nonatomic, strong)NSString * cityStr;
@property(nonatomic, strong)NSString * clientStr;
@property(nonatomic, strong)UILabel *clientLab;
@property(nonatomic, strong)UILabel *provinceLab;
@property(nonatomic, strong)UILabel *cityLab;
@property(nonatomic, strong)TPKeyboardAvoidingScrollView * scrollView;

@end
@implementation RegisterNextViewController
- (void)initView
{
    [super initView];
    [self setTitle:@"注册"];
    [self.navBar createRightBtn:@"已有账号" block:^{
        //登录界面
        LoginViewController *registerVC =[[LoginViewController alloc]init];
        [self pushController:registerVC];
    }];
    _eyeClick =0;
    _selectClick=0;
    _cityCodeAr=[[NSMutableArray alloc]init];
    _provinceAr= [[NSMutableArray alloc] init];
    _cityAr =[[NSMutableArray alloc]init];
    _clientAr =[[NSMutableArray alloc]init];
    [self layoutView];
    //请求城市省份
    [CClass HttpRequestTask:YES withUrl:@"select_showAreaSelect" withData:nil notifyError:YES onSuccess:^(BaseModel *model) {
        
        _provinceAr =[model.B_data objectForKey:@"province"];
        _cityAr=[model.B_data objectForKey:@"city"];
        [_pickerView1 reloadAllComponents];

        
        
    } onError:^(BaseModel *model) {
        
    }];
    //请求所属服务商
    [CClass HttpRequestTask:YES withUrl:@"select_showServiceSelect" withData:nil notifyError:YES onSuccess:^(BaseModel *model) {
        _clientAr =(NSMutableArray*)model.B_data;
        [_pickerView3 reloadAllComponents];
    } onError:^(BaseModel *model) {
        
    }];
    
    _bgView1 =[[BankView alloc]initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight)witnOriginY:WindowHeight/3 withTitle:@"所在省份"];
    _bgView1.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.4];
    [self.view bringSubviewToFront:_bgView1];
    [self.view addSubview:_bgView1];
    _bgView1.hidden=YES;
    _pickerView1=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, WindowWidth, WindowHeight/3-40)];
    _pickerView1.delegate=self;
    _pickerView1.dataSource=self;
    _pickerView1.backgroundColor =[UIColor whiteColor];
    _pickerView1.showsSelectionIndicator=YES;
    [_bgView1.whiteView addSubview:_pickerView1];
    __block typeof(self) blockself = self;
    [_bgView1 setSubmitBtnPress:^{
        blockself.provinceLab.text=blockself.provinceStr;
        blockself.provinceLab.textColor=[UIColor blackColor];
        
    }];
    
    _bgView2 =[[BankView alloc]initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight)witnOriginY:WindowHeight/3 withTitle:@"所在县市"];
    _bgView2.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.4];
    [self.view bringSubviewToFront:_bgView2];
    [self.view addSubview:_bgView2];
    _bgView2.hidden=YES;
    _pickerView2=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, WindowWidth, WindowHeight/3-40)];
    _pickerView2.delegate=self;
    _pickerView2.dataSource=self;
    _pickerView2.backgroundColor =[UIColor whiteColor];
    _pickerView2.showsSelectionIndicator=YES;
    [_bgView2.whiteView addSubview:_pickerView2];
    [_bgView2 setSubmitBtnPress:^{
        blockself.cityLab.text=blockself.cityStr;
        blockself.cityLab.textColor=[UIColor blackColor];
        
    }];
    _bgView3 =[[BankView alloc]initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight)witnOriginY:WindowHeight/3 withTitle:@"所属服务商"];
    _bgView3.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.4];
    [self.view bringSubviewToFront:_bgView3];
    [self.view addSubview:_bgView3];
    _bgView3.hidden=YES;
    _pickerView3=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, WindowWidth, WindowHeight/3-40)];
    _pickerView3.delegate=self;
    _pickerView3.dataSource=self;
    _pickerView3.backgroundColor =[UIColor whiteColor];
    _pickerView3.showsSelectionIndicator=YES;
    [_bgView3.whiteView addSubview:_pickerView3];
    [_bgView3 setSubmitBtnPress:^{
        blockself.clientLab.text=blockself.clientStr;
        blockself.clientLab.textColor=[UIColor blackColor];
        
    }];
}
- (void)layoutView
{
    _scrollView =[[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-64)];
    _scrollView.contentSize=CGSizeMake(WindowWidth, WindowHeight+100);
    _scrollView.backgroundColor =BackColor;
    [self.view addSubview:_scrollView];
    UIColor *color = C(@"b9b7b7");
    
     NSArray *ar =[[NSArray alloc]initWithObjects:@"姓名",@"所属服务商",@"省份",@"县市",@"密码",nil];
    for (int i=0; i<ar.count; i++) {
        UILabel*lab=[[UILabel alloc]init];
        lab.frame =CGRectMake(25, (39+48)*i, WindowWidth-25, 39);
        lab.font= F(14);
        [_scrollView addSubview:lab];
       
        lab.text =[ar objectAtIndex:i];
        UIView *bgView =[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(lab.frame), WindowWidth, 48)];
        bgView.backgroundColor =[UIColor whiteColor];
        [_scrollView addSubview:bgView];
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, WindowWidth, 0.5)];
        line.backgroundColor =LineColor;
        [bgView addSubview:line];
        UILabel*line1=[[UILabel alloc]initWithFrame:CGRectMake(0, 47.5, WindowWidth, 0.5)];
        line1.backgroundColor =LineColor;
        [bgView addSubview:line1];
        if(i==0)
        {
            
            _nameText =[[UITextField alloc]init];
            _nameText.font =F(12);
            [_nameText setBk_shouldChangeCharactersInRangeWithReplacementStringBlock:^BOOL(UITextField *tfd, NSRange range, NSString *str) {
                if ([[[UITextInputMode currentInputMode]primaryLanguage] isEqualToString:@"emoji"]) {
                    return NO;
                }
                return YES;
            }];
            [_nameText bk_addEventHandler:^(id sender) {
                
                UITextPosition *position = [_nameText positionFromPosition:[_nameText markedTextRange] offset:0];
                if (position) {
                    return;
                }
                NSInteger maxLength = 20;
                if (maxLength > 0) {
                    NSInteger splitcount;
                    if (splitcount > 0) {
                        maxLength = maxLength + maxLength /splitcount - (maxLength % splitcount == 0 ? 1 : 0);
                    }
                    if (_nameText.text.length > maxLength) {
                        _nameText.text = [_nameText.text substringWithRange:NSMakeRange(0, maxLength)];
                    }
                    //移除表情
                    NSString *newStr= [CClass disable_emoji:_nameText.text];
                    _nameText.text=newStr;
                    
                    
                }
                
            } forControlEvents:UIControlEventEditingChanged];
            _nameText.tag =100+i;
            [bgView addSubview:_nameText];
            _nameText.frame =CGRectMake(25, 0.5, WindowWidth-50, 47);
            _nameText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入您的姓名" attributes:@{NSForegroundColorAttributeName: color}];
        }else if (i==1) {
            
            UIButton *selectBtn =[UIButton buttonWithType:UIButtonTypeCustom];
            [bgView addSubview:selectBtn];
            selectBtn.frame =CGRectMake(0, 0.5, WindowWidth, 47);
            
            UIImage *image =[UIImage imageNamed:@"Ico_register_down"];
            _clientLab=[[UILabel alloc]init];
            _clientLab.frame =CGRectMake(25, 0, WindowWidth-55-image.size.width, 47);
            _clientLab.font= F(12);
            _clientLab.text =@"请选择所属服务商";
            _clientLab.textColor=color;
            [selectBtn addSubview:_clientLab];
            
            [selectBtn bk_addEventHandler:^(id sender) {
                [self.view endEditing:YES];
                _bgView3.hidden=NO;
                int i = 0;
                for (NSDictionary *province in _clientAr) {
                    if ([province[@"name"] isEqualToString:_clientLab.text]) {
                        [_pickerView3 selectRow:i inComponent:0 animated:YES];
                        break;
                    }
                    i ++;
                }
                if (i == _clientAr.count) {
                    NSDictionary *dic =[_clientAr objectAtIndex:0];
                    self.clientStr=[dic objectForKey:@"name"];
                    _client=[dic objectForKey:@"uuid"];
                }
              
                [UIView animateWithDuration:0.5 animations:^{
                    _bgView3.whiteView.frame=CGRectMake(0,WindowHeight/3*2 , WindowWidth, WindowHeight/3);
                } completion:nil];
                
                
                
            } forControlEvents:UIControlEventTouchUpInside];
            
        }else if (i==2) {
            
            UIButton *selectBtn =[UIButton buttonWithType:UIButtonTypeCustom];
            [bgView addSubview:selectBtn];
            selectBtn.frame =CGRectMake(0, 0.5, WindowWidth, 47);
            
           UIImage *image =[UIImage imageNamed:@"Ico_register_down"];
            _provinceLab=[[UILabel alloc]init];
            _provinceLab.frame =CGRectMake(25, 0, WindowWidth-55-image.size.width, 47);
            _provinceLab.font= F(12);
            _provinceLab.text =@"请选择所在省份";
            _provinceLab.textColor=color;
            [selectBtn addSubview:_provinceLab];
            
            [selectBtn bk_addEventHandler:^(id sender) {
                [self.view endEditing:YES];
                _bgView1.hidden=NO;
                _isProvince = true;

                NSDictionary *dic =[_provinceAr objectAtIndex:0];
                self.provinceStr=[dic objectForKey:@"name"];
                
                
                [UIView animateWithDuration:0.5 animations:^{
                    _bgView1.whiteView.frame=CGRectMake(0,WindowHeight/3*2 , WindowWidth, WindowHeight/3);
                } completion:nil];
                
                
                
            } forControlEvents:UIControlEventTouchUpInside];
            
        }else if(i==3){
            
                UIButton *selectBtn =[UIButton buttonWithType:UIButtonTypeCustom];
                [bgView addSubview:selectBtn];
                selectBtn.frame =CGRectMake(0, 0.5, WindowWidth, 47);
                
                UIImage *image =[UIImage imageNamed:@"Ico_register_down"];
                _cityLab=[[UILabel alloc]init];
                _cityLab.frame =CGRectMake(25, 0, WindowWidth-55-image.size.width, 47);
                _cityLab.font= F(12);
                _cityLab.text =@"请选择所在县市";
                _cityLab.textColor=color;
                [selectBtn addSubview:_cityLab];

                [selectBtn bk_addEventHandler:^(id sender) {
                    if (_isProvince==false) {
                      
                        [CClass showMessage:@"请先选择所在省份"];
                        return ;
                    }else
                    {
                        [self.view endEditing:YES];
                        _bgView2.hidden=NO;
                        
                        NSDictionary *dic =[_provinceAr objectAtIndex:0];
                        for (int i=0; i<_cityAr.count; i++) {
                            NSDictionary *dicCity=[[NSDictionary alloc]init];
                            dicCity =[_cityAr objectAtIndex:i];
                            if ([[dicCity objectForKey:@"parent_code"] isEqual:[dic objectForKey:@"code"]]) {
                                [_cityCodeAr addObject:dicCity];
                                [_pickerView2 reloadAllComponents];
                            }
                        }
                        
                        self.cityStr=[[_cityAr objectAtIndex: 0] objectForKey:@"name"];

                        [UIView animateWithDuration:0.5 animations:^{
                            _bgView2.whiteView.frame=CGRectMake(0,WindowHeight/3*2 , WindowWidth, WindowHeight/3);
                        } completion:nil];
                    }
                    
                    
                    
                    
                } forControlEvents:UIControlEventTouchUpInside];

            
            
            }else if(i==4)
            {
                _password =[[CTextField alloc]initWithFrame:CGRectMake(25, 0.5, WindowWidth-130, 47)];
                _password.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入密码" attributes:@{NSForegroundColorAttributeName: color}];
                _password.secureTextEntry =YES;
                _password.font =F(12);
                [_password setInputType:CTextFieldInputTypePassword];
                [_password setBk_shouldChangeCharactersInRangeWithReplacementStringBlock:^BOOL(UITextField *textField, NSRange range, NSString *str) {
                    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet];
                    NSString *filtered = [[str componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
                    return [str isEqualToString:filtered];
                }];
                
                [_password setMinLength:8 msg:@"请输入8-20位密码"];
                [_password setMaxLength:20 LengthChangeBlock:nil];
                [_password bk_addEventHandler:^(id sender) {
                    //移除表情
                    NSString *newStr= [CClass disable_emoji:_password.text];
                    _password.text=newStr;
                    
                    
                } forControlEvents:UIControlEventEditingChanged];
                [bgView addSubview:_password];
                UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
                button.frame =CGRectMake(WindowWidth-86, 7.5, 86, 33);
                [button setImage:[UIImage imageNamed:@"Ico_register_noEye"] forState:UIControlStateNormal];
                [button bk_addEventHandler:^(id sender) {
                    _eyeClick++;
                    if (_eyeClick%2==0) {
                        _password.secureTextEntry=YES;
                        [button setImage:[UIImage imageNamed:@"Ico_register_noEye"] forState:UIControlStateNormal];
                        
                    }else{
                        _password.secureTextEntry=NO;
                        [button setImage:[UIImage imageNamed:@"Ico_register_eye"] forState:UIControlStateNormal];
                    }
                } forControlEvents:UIControlEventTouchUpInside];
                [bgView addSubview:button];
            }
    }

    UIImage *image1 =[UIImage imageNamed:@"Ico_register_noSelect"];
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    [_scrollView addSubview:button];
    button.frame =CGRectMake(30, 86*5+10, 30, 30);
    [button setImage:image1 forState:UIControlStateNormal];
    button.titleLabel.font =F(14);
    [button bk_addEventHandler:^(id sender) {
        _selectClick++;
        if (_selectClick%2==0) {
            
            [button setImage:[UIImage imageNamed:@"Ico_register_noSelect"] forState:UIControlStateNormal];
            
        }else{
            
            [button setImage:[UIImage imageNamed:@"Ico_register_select"] forState:UIControlStateNormal];
        }
        
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    UILabel*agreeLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(button.frame)+5, 86*5+10, WindowWidth-20-CGRectGetMaxX(button.frame), 30)];
    [_scrollView addSubview:agreeLab];
    
    
    agreeLab.font= F(14);
    NSString *string =@"同意并接受邮易维用户隐私条款";
    NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:string];
    
    
    [str addAttribute:NSForegroundColorAttributeName value:C(@"888888") range:NSMakeRange(0, 5)];
    [str addAttribute:NSForegroundColorAttributeName value:MainColor range:NSMakeRange(5, string.length-5)];
    
    agreeLab.attributedText =str;
    agreeLab.userInteractionEnabled=YES;
    [agreeLab bk_whenTapped:^{
        //进入协议
        RegusterAgreementViewController *regusterAgreemVC =[[RegusterAgreementViewController alloc]init];
        [self pushController:regusterAgreemVC];
        
    }];
    
    
    UIButton *agreeBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    agreeBtn.frame =CGRectMake(33, CGRectGetMaxY(button.frame)+10, WindowWidth-66, 35);
    [agreeBtn setBackgroundColor:MainColor];
    agreeBtn.layer.masksToBounds=YES;
    agreeBtn.layer.cornerRadius=8;
    [agreeBtn setTitle:@"注册" forState:UIControlStateNormal];
    agreeBtn.titleLabel.font =F(15);
    [agreeBtn bk_addEventHandler:^(id sender) {
        
        
        if (_nameText.text.length == 0) {
            [CClass showMessage:@"请输入姓名!"];
            return ;
        }
        if (_client==nil) {
            [CClass showMessage:@"请选择所属服务商!"];
            return;
        }
        if ([_provinceLab.text isEqualToString:@"请选择所在省份"]) {
            [CClass showMessage:@"请选择所在省份!"];
            return;
        }
        if ([_cityLab.text isEqualToString:@"请选择所在县市"]) {
            [CClass showMessage:@"请选择所在县市!"];
            return;
        }
        if (_password.text.length==0) {
            [CClass showMessage:@"请输入8-20位密码!"];
            return;
        }
        if (_password.text.length>20) {
            [CClass showMessage:@"请输入8-20位密码!"];
            return;
        }
        if (!_password.verfiy) {
            return;
        }
        if (_selectClick%2==0){
            [CClass showMessage:@"请同意隐私条款!"];
            return;
            
        }
        
        [self setIsLoading:YES];
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:[CClass base64:_password.text] forKey:@"password"];
        [dic setObject:_nameText.text forKey:@"name"];
        [dic setObject:@"02" forKey:@"customerType"];
        [dic setObject:_cityLab.text forKey:@"city"];
        [dic setObject:_provinceLab.text forKey:@"province"];
        [dic setObject:_client forKey:@"serviceProvider"];

        

        //银行的编号
        
        [CClass HttpRequestTask:YES withUrl:@"app_registryRegistry" withData:dic notifyError:YES onSuccess:^(BaseModel *model) {
            
            //注册之后进行一个登陆请求
            //未通过审核
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setObject:self.phone forKey:@"mobile"];
            [dic setObject:[CClass base64:_password.text] forKey:@"password"];
            [dic setObject:[CClass getUUID] forKey:@"imei"];
            [dic setObject:@"02" forKey:@"customerType"];
            
            [CClass HttpRequestTask:YES withUrl:@"app_login" withData:dic notifyError:YES onSuccess:^(BaseModel *model) {
                [(AppDelegate *)[[UIApplication sharedApplication] delegate] registerPush];

                [self setIsLoading:NO];
                ////注册成功 进入首页
                self.headUrl=[model.B_data objectForKey:@"headImg"];
                [CClass saveCacheData:self.phone key:NSUD_Mobile];
                [CClass saveCacheData:[model.B_data objectForKey:@"name"] key:NSUD_Name];
                [CClass saveCacheData:[model.B_data objectForKey:@"uuid"] key:NSUD_Uuid];
                [CClass saveCacheData:[model.B_data objectForKey:@"authtoken"] key:NSUD_Token];
                [CClass saveCacheData:[model.B_data objectForKey:@"uuid"]key:NSUD_UUID];
                [CClass saveCacheData:[model.B_data objectForKey:@"state"] key:NSUD_state];
                if([F_NSpace([model.B_data  objectForKey:@"city"]) isEqualToString:@""]){
                    
                }else
                {
                    [CClass saveCacheData:[model.B_data objectForKey:@"city"]key:NSUD_City];
                    
                }
                if([F_NSpace([model.B_data  objectForKey:@"province"]) isEqualToString:@""]){
                    
                }else
                {
                    [CClass saveCacheData:[model.B_data objectForKey:@"province"]key:NSUD_Province];
                    
                }
                [CClass showMessage:@"注册成功"];
                [self enter];
                //	获取七牛云存储信息
                [CClass HttpRequestTask:YES withUrl:@"warninglist_getQiniuInfo" withData:nil notifyError:YES onSuccess:^(BaseModel *model) {
                    [CClass saveCacheData:[model.B_data objectForKey:@"qnDomain"] key:qnDomain];
                    [CClass saveCacheData:[model.B_data objectForKey:@"qnScope"]key:qnScope];
                    [CClass saveCacheData:[model.B_data objectForKey:@"qnAk"] key:qnAk];
                    [CClass saveCacheData:[model.B_data objectForKey:@"qnSk"]key:qnSk];
                    //存储头像
                    NSString *string=[NSString stringWithFormat:@"%@%@",[CClass getCacheData:qnDomain],self.headUrl];
                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:string]]];
                    [CClass SaveImageToLocal:image Keys:NSUD_HeadImg];
                } onError:^(BaseModel *model) {
                    
                }];
                
            } onError:^(BaseModel *model) {
                
            }];
            
        } onError:^(BaseModel *model) {
            
            
        }];
        
        
    } forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:agreeBtn];
    
    
}
- (void) enter{
    [self.navigationController popToRootViewControllerAnimated:NO];
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate enter];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
    
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 35;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView==_pickerView1) {
        return _provinceAr.count;
  
    }else if(pickerView==_pickerView2)
    {
        return _cityCodeAr.count;
    }else
    {
        return _clientAr.count;

    }
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
     if (pickerView==_pickerView1) {
         NSDictionary *dic =[_provinceAr objectAtIndex:row];
         return [dic objectForKey:@"name"];
     }else if(pickerView==_pickerView2)
     {
         NSDictionary *dic =[_cityCodeAr objectAtIndex:row];
         return [dic objectForKey:@"name"];
     }else
     {
         NSDictionary *dic =[_clientAr objectAtIndex:row];
         return [dic objectForKey:@"name"];

     }
  
    
    
    
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView==_pickerView1) {
            NSDictionary *dic =[_provinceAr objectAtIndex:row];
           self.provinceStr=[dic objectForKey:@"name"];
        
        for (int i=0; i<_cityAr.count; i++) {
            NSDictionary *dicCity=[[NSDictionary alloc]init];
            dicCity =[_cityAr objectAtIndex:i];
            if ([[dicCity objectForKey:@"parent_code"] isEqual:[dic objectForKey:@"code"]]) {
                [_cityCodeAr addObject:dicCity];
            }
        }
        
        [_pickerView2 reloadAllComponents];


    }else if(pickerView == _pickerView2)
    {
        NSDictionary *dic =[_cityCodeAr objectAtIndex:row];
        self.cityStr=[dic objectForKey:@"name"];
    }else
    {
        NSDictionary *dic =[_clientAr objectAtIndex:row];
        self.clientStr=[dic objectForKey:@"name"];
        _client=[dic objectForKey:@"uuid"];
    }

    
    
}
@end
